<template>
  <div>
    <a-modal v-model:visible="visible">
      <template #title> 混楂 </template>
      <a-form :model="form" :rules="rules" ref="formRef" @submit="handleSubmit">
        <a-form-item label="初始酒罐" name="init_tank_name">
          <a-input v-model="form.init_tank_name" readonly />
        </a-form-item>
        <a-form-item label="现有库存" name="now_tank_num">
          <a-input v-model="form.now_tank_num" readonly>
            <template #append> 公斤 </template>
          </a-input>
        </a-form-item>
        <a-form-item label="目标酒罐" name="new_tank_id">
          <a-select
            v-model="form.new_tank_id"
            placeholder="请选择目标酒罐（只可选择类别为混楂的酒罐）"
            allow-clear
          >
            <a-option
              v-for="item in tableData"
              :disabled="item.wine_tank_status !== '3'"
              :key="item.id"
              :value="item.id"
              :label="item.wine_tank_name"
            ></a-option>
          </a-select>
        </a-form-item>
        <a-form-item label="数量" name="wine_num">
          <a-input-number v-model="form.wine_num" placeholder="请输入数量">
            <template #append> 公斤 </template>
          </a-input-number>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" @click="save">确定</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';
import { Message } from '@arco-design/web-vue';
import { saveWineHun } from '@/api/winepro';
const props = defineProps({
  tableData: { type: Array },
  getTankList:{type:Function}
});
const save = async () => {
  if (form.wine_num > form.now_tank_num) {
    Message.error('数量不能大于现有库存');
    return;
  }
  const { code, message } = await saveWineHun(form);
  if (code === 200) {
    props.getTankList()
    Message.success(message);
    visible.value = false;
  }
};
const visible = ref(false);
const form = reactive({
  init_tank_id: '',
  init_tank_name: '',
  now_tank_num: '',
  new_tank_id: '',
  wine_num: '', // 数量
});
const openDialog = (record) => {
  form.init_tank_id = record.id;
  form.init_tank_name = record.wine_tank_name;
  form.now_tank_num = record.wine_tank_stock;
  visible.value = true;
};
defineExpose({
  openDialog,
});
</script>

<style lang="less" scoped></style>